home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2008 February / PCWFEB08.iso / Software / Freeware / Miro 1.0 / Miro_Installer.exe / xulrunner / python / test / olddatabaseupgradetest.py < prev    next >
Encoding:
Python Source  |  2007-11-12  |  3.9 KB  |  106 lines

  1. import os
  2. import shutil
  3. import tempfile
  4. import unittest
  5.  
  6. import database
  7. import olddatabaseupgrade
  8. import storedatabase
  9. import databaseupgrade
  10. import databasesanity
  11. import resources
  12.  
  13. from test.framework import EventLoopTest
  14.  
  15. class TestConvert(EventLoopTest):
  16.     def setUp(self):
  17.         storedatabase.skipOnRestore = True
  18.         self.utilDotFailedOkay = True
  19.         self.tmpPath = tempfile.mktemp()
  20.         EventLoopTest.setUp(self)
  21.  
  22.     def tearDown(self):
  23.         storedatabase.skipOnRestore = False
  24.         try:
  25.             os.unlink(self.tmpPath)
  26.         except:
  27.             pass
  28.         EventLoopTest.tearDown(self)
  29.  
  30.     def checkConversion(self):
  31.         olddatabaseupgrade.convertOldDatabase(self.tmpPath)
  32.         objects = storedatabase.restoreObjectList(self.tmpPath)
  33.         # Not sure what kind of checks we can do on the restored objects,
  34.         # let's make sure that they are there at least.  Also, make sure the
  35.         # sanity tests can recover from any errors
  36.         self.assert_(len(objects) > 0)
  37.         databasesanity.checkSanity(objects, fixIfPossible=True, quiet=True,
  38.                 reallyQuiet=True)
  39.  
  40.     def testConvert82(self):
  41.         shutil.copyfile(resources.path("testdata/olddatabase-0.8.2"), 
  42.                 self.tmpPath)
  43.         self.checkConversion()
  44.         shutil.copyfile(resources.path("testdata/olddatabase-0.8.2-2"), 
  45.                 self.tmpPath)
  46.         self.checkConversion()
  47.  
  48.     def testConvert81(self):
  49.         shutil.copyfile(resources.path("testdata/olddatabase-0.8.1"), 
  50.                 self.tmpPath)
  51.         self.checkConversion()
  52.  
  53.     def testBug2003(self):
  54.         # the olddatabase.bug.2003 file is a database I (BDK) created in a
  55.         # fairly hackish way to simulate old databases like the one reported
  56.         # in 2003 and 2515.  The testBug2515 test is much more comprehensive,
  57.         # but I figure we may as well leave this one in.
  58.         shutil.copyfile(resources.path("testdata/olddatabase.bug.2003"),
  59.                 self.tmpPath)
  60.         self.checkConversion()
  61.  
  62.     def testBug2515(self):
  63.         # Real life database that has the phantom feed with downloaders bug.
  64.         # This one came from david moore, and was attached to #2515
  65.         shutil.copyfile(resources.path("testdata/olddatabase.bug.2515"),
  66.                 self.tmpPath)
  67.         self.checkConversion()
  68.  
  69.     def testBug2685(self):
  70.         # Database created by ben to simulate bug #2685
  71.         shutil.copyfile(resources.path("testdata/olddatabase.bug.2685"),
  72.                 self.tmpPath)
  73.         self.checkConversion()
  74.  
  75.     def testBug3163(self):
  76.         # Database created by ben to simulate bug #3163 (channel guide doesn't
  77.         # have an id attribute).
  78.         shutil.copyfile(resources.path("testdata/olddatabase.bug.3163"),
  79.                 self.tmpPath)
  80.         self.checkConversion()
  81.  
  82.     def testBug4039(self):
  83.         # Test that when databases fail sanity tests, we don't call
  84.         # onRestore() for the objects that failed.  olddatabase.bug.4039
  85.         # contains a database an item whose feed doesn't exist.
  86.         shutil.copyfile(resources.path("testdata/olddatabase.bug.4039"),
  87.                 self.tmpPath)
  88.         db = database.DynamicDatabase()
  89.         storedatabase.skipOnRestore = False
  90.         storedatabase.restoreDatabase(db=db, pathname=self.tmpPath)
  91.         # if onRestore() was called, we would have the icon cache update
  92.         # scheduled as an idle callback
  93.         self.assertEquals(len(db.objects), 0)
  94.         self.assert_(not self.hasIdles())
  95.  
  96.     def testBug4039part2(self):
  97.         # On the other hand, for database that are normal, we should call 
  98.         # onRestore()
  99.         shutil.copyfile(resources.path("testdata/olddatabase.bug.4039.part2"),
  100.                 self.tmpPath)
  101.         db = database.DynamicDatabase()
  102.         storedatabase.skipOnRestore = False
  103.         storedatabase.restoreDatabase(db=db, pathname=self.tmpPath)
  104.         self.assertEquals(len(db.objects), 2)
  105.         self.assert_(self.hasIdles())
  106.